package java实验七;

public class 程序二 {
 public static void main(String[] args) {
     // 创建一个半径为1的圆
     Circle circle1 = new Circle();
     System.out.println("The area of a circle with radius " + circle1.radius + " is " + circle1.getArea());

     // 创建一个半径为25的圆
     Circle circle2 = new Circle(25);
     System.out.println("The area of a circle with radius " + circle2.radius + " is " + circle2.getArea());

     // 创建一个半径为125的圆
     Circle circle3 = new Circle(125);
     System.out.println("The area of a circle with radius " + circle3.radius + " is " + circle3.getArea());

     // 修改circle2的半径
     circle2.radius = 150;
     System.out.println("The area of a circle with radius " + circle2.radius + " is " + circle2.getArea());
 }
}
class Circle {
 // 成员变量
 double radius;

 // 构造方法
 Circle() {
     // 初始化radius为1
     radius = 1;
 }

 // 构造方法
 Circle(double newRadius) {
     // 将传入的新半径赋值给radius
     radius = newRadius;
 }

 // 返回圆的面积
 double getArea() {
     // 计算并返回面积
     return radius * radius * Math.PI;
 }

 // 返回圆的周长
 double getPerimeter() {
     // 计算并返回周长
     return 2 * radius * Math.PI;
 }

 // 设置新的半径
 void setRadius(double newRadius) {
     // 更新radius的值
     radius = newRadius;
 }
}